|
|
|
|
|
|
|
Figure 4.7
Option buttons can be used to
provide a list of fixed choices. |
|
|
|
|
|
|
|
|
Use the Click event if you want to take an action when users select an option. This method is useful when you are using option buttons that are in a control array, as in the following example: |
|
|
|
|
|
|
|
|
Private Sub optWash_Click(Index As Integer)
Select Case Index
Case 0
MsgBox "You selected: Normal"
Case 1
MsgBox "You selected: Heavy Duty"
Case 2
MsgBox "You selected: Pots and Pans"
End Select
End Sub |
|
|
|
|
|
|
|
|
Do not write any code in the option button events. Instead, use an if statement to check their state, as shown here: |
|
|
|
|
|
|
|
|
Private Sub cmdStartWash_Click()
If optHeavy = True Then
DoHeavyWash
Else
DoNormalWash
End If
End Sub |
|
|
|
|
|
|
|
|
This second method is useful if you do not want something to happen immediately when users select options. |
|
|
|
|
|
|
|
|
You may be wondering whether it is ever possible to have multiple option buttons on a form selected at the same time. The answer is yes, but you have to separate the option buttons into groups by using container controls. Using a container, such as the Frame control discussed later in this chapter, allows you to group option buttons, as shown in Figure 4.8. |
|
|
|
|
|
|
|
|
Figure 4.8
To create multiple groups of option
buttons, place them in a container
such as a frame or picture box. |
|
|
|
|
|